package com.me.jingdongshop.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.me.jingdongshop.R;

/**
 * Created by Tm on 2017/5/9.
 */

public class ProductOrderAdapter extends BaseAdapter {
    MyHolder myHolder;

    private Context mContext;

    String [] stateDatas = {"综合","上架时间","评论从高到低"};

    public ProductOrderAdapter(Context context) {
        mContext = context;
    }

    @Override
    public int getCount() {
        return stateDatas.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView==null){
            myHolder= new MyHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.product_lv_item, parent, false);
            myHolder.state = (TextView) convertView.findViewById(R.id.state);
            myHolder.select = (ImageView) convertView.findViewById(R.id.select);
            myHolder.relv=(RelativeLayout)convertView.findViewById(R.id.re_lv);

            convertView.setTag(myHolder);
    }else {
            myHolder = (MyHolder) convertView.getTag();
        }
        //初始化数据
        myHolder.state.setText(stateDatas[position]);

        myHolder.relv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myHolder.state.setTextColor(Color.RED);
                myHolder.select.setVisibility(View.VISIBLE);
            }
        });

        return convertView;
    }

    class MyHolder {

        private TextView state;
        private ImageView select;
        private RelativeLayout relv;
    }
}
